package com.weiai.wedding.entity.cases;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.weiai.wedding.util.ConUtils;


/**
 * 案例
 * @author wangweiheng
 *
 */
@Entity
@Table(name="cases")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Cases {
	/**
	 * 彩信ID
	 */
	private Long casesId;
	/**
	 * 彩信名称
	 */
	private String casesName;
	/**
	 * 彩信说明
	 */
	private String casesDesc;
	/**
	 * 彩信标题
	 */
	private String casesTitle;
	/**
	 * 彩信smil
	 */
	private String casesSmil;
	/**
	 * 创建时间
	 */
	private Date createDate;
	/**
	 * 创建人
	 */
	private String createBy;
	/**
	 * 状态
	 */
	private String status;
	/**
	 * 彩信内容
	 */
	private List<CasesContent> casesContentList = new ArrayList<CasesContent>();
	/**
	 * 格式化时间
	 */
	private String createDateStr;
	/**
	 * 审核意见
	 */
	private String auditDesc;
	/**
	 * 状态名称
	 */
	private String statusName;
	/**
	 * 资源路径
	 */
	private String resourcesDir;
	private List<CasesContInfo> casesInfoList = new ArrayList<CasesContInfo>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getCasesId() {
		return casesId;
	}
	public void setCasesId(Long casesId) {
		this.casesId = casesId;
	}
	
	@Column(nullable=false,length = 50)
	public String getCasesName() {
		return casesName;
	}
	public void setCasesName(String casesName) {
		this.casesName = casesName;
	}
	@Column(nullable=false,length = 512)
	public String getCasesDesc() {
		return casesDesc;
	}
	public void setCasesDesc(String casesDesc) {
		this.casesDesc = casesDesc;
	}
	@Column(length=512)
	public String getResourcesDir() {
		return resourcesDir;
	}
	public void setResourcesDir(String resourcesDir) {
		this.resourcesDir = resourcesDir;
	}
	@Column(length=100)
	public String getCasesTitle() {
		return casesTitle;
	}
	public void setCasesTitle(String casesTitle) {
		this.casesTitle = casesTitle;
	}
	
	@Column(length=5000)
	public String getCasesSmil() {
		return casesSmil;
	}
	public void setCasesSmil(String casesSmil) {
		this.casesSmil = casesSmil;
	}
	
	@Column(nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
		this.setCreateDateStr(ConUtils.formatDate(createDate,"yyyy-MM-dd"));
	}
	
	@Column(nullable=false,length = 50)
	public String getCreateBy() {
		return createBy;
	}
	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}
	
	@Column(length = 5)
	public String getStatus() {
		return status;
	}
	
	public void setStatus(String status) {
		this.status = status;
		if("S".equals(status)){
			this.setStatusName("待审核");
		}
		if("A".equals(status)){
			this.setStatusName("已通过");
		}
		if("R".equals(status)){
			this.setStatusName("驳回");
		}
		if("WaDEL".equals(status)){
			this.setStatusName("等待删除审核");
		}
	}
	@Column(length=512)
	public String getAuditDesc() {
		return auditDesc;
	}
	public void setAuditDesc(String auditDesc) {
		this.auditDesc = auditDesc;
	}
	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH,   
            CascadeType.REMOVE, CascadeType.MERGE }, fetch = FetchType.EAGER, mappedBy = "cases")
	@JsonIgnore
    public List<CasesContent> getCasesContentList() {
		return casesContentList;
	}
	public void setCasesContentList(List<CasesContent> casesContentList) {
		this.casesContentList = casesContentList;
	}
	
	
	public void addCasesContentList(CasesContent mc){
		mc.setCases(this);
		this.casesContentList.add(mc);
	}
	
	@Transient
	public String getCreateDateStr() {
		return createDateStr;
	}
	public void setCreateDateStr(String createDateStr) {
		this.createDateStr = createDateStr;
	}
	
	@Transient
	public List<CasesContInfo> getCasesInfoList() {
		return casesInfoList;
	}
	public void setCasesInfoList(List<CasesContInfo> casesInfoList) {
		this.casesInfoList = casesInfoList;
	}
	@Transient
	public String getStatusName() {
		return statusName;
	}
	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}
	
	
}
